﻿//----------------------------------------------------------------------------------------------------
// IAction is the base class for actions that the player can/will/has performed.
//----------------------------------------------------------------------------------------------------
package HG.Actions
{
	import HG.Visual.VisualConnection;
	
	import HG.GameService;
	import HG.Managers.LevelManager;
	import HG.Visual.VisualNode;
	import HG.Managers.PlayerManager;

	public class IAction
	{
		var m_lastError:String;
		
		var m_nodeID:Number;
		var m_playerID:Number;
		var m_type:Number;
		
		var m_timeToComplete:Number;
		var m_executeCount:Number;
		
		//----------------------------------------------------------------------------------------------------
		public function IAction(playerID:Number, nodeID:Number, type:Number)
		{
			m_lastError = "None";
			
			m_playerID = playerID;
			m_nodeID = nodeID;
			m_type = type;
			
			m_timeToComplete = 1;
			m_executeCount = 0;
			
			var levelManager:LevelManager = GameService.GetInstance().GetLevelManager();
			var visNode:VisualNode = levelManager.GetVisualNode(m_nodeID);
			
			visNode.SetPendingAction(this);
		}
		
		//----------------------------------------------------------------------------------------------------
		public function GetType():Number
		{
			return m_type;
		}
		
		//----------------------------------------------------------------------------------------------------
		public function GetOwner():Number
		{
			return m_playerID;
		}
		
		//----------------------------------------------------------------------------------------------------
		public function GetTargetNodeID():Number
		{
			return m_nodeID;
		}
		
		//----------------------------------------------------------------------------------------------------
		public function GetLastError():String
		{
			return m_lastError;
		}
		
		//----------------------------------------------------------------------------------------------------
		public function Execute():Boolean
		{
			m_executeCount++;
			
			m_lastError = "Base class actions cannot be executed."
			return false;
		}
		
		//----------------------------------------------------------------------------------------------------
		public function GetIsComplete():Boolean
		{
			if (m_executeCount >= m_timeToComplete)
			{
				return true;
			}
			
			return false;
		}
		
		//----------------------------------------------------------------------------------------------------
	}
}